package cn.edu.nwsuaf.examcenter.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.nwsuaf.examcenter.pojo.College;
import cn.edu.nwsuaf.examcenter.pojo.Grade;
import cn.edu.nwsuaf.examcenter.pojo.Major;
import cn.edu.nwsuaf.examcenter.pojo.Sclass;
import cn.edu.nwsuaf.examcenter.service.CollegeService;
import cn.edu.nwsuaf.examcenter.service.GradeService;
import cn.edu.nwsuaf.examcenter.service.MajorService;
import cn.edu.nwsuaf.examcenter.service.SclassService;

@Controller
@RequestMapping(value="/sclass")
public class SclassController {
	
	@Resource(name="sclassService")
	private SclassService SclassService;
	@Resource(name="collegeService")
	private CollegeService collegeService;
	@Resource(name="majorService")
	private MajorService majorService;
	@Resource(name="gradeService")
	private GradeService gradeService;
	
	
	@RequestMapping(value="/loadSclass")
	public String loadSclass(@RequestParam(value="key", required=false)String key, 
			@RequestParam(value="p",required=false)String p, 
			ModelMap modelMap){
		SclassService.loadSclass(modelMap);
		return "exam/sclass-list";
	}
	
	@ResponseBody
	@RequestMapping(value="/addSclass")
	public String addSclass(@ModelAttribute Sclass Sclass){
		SclassService.saveSclass(Sclass);
		return "success";
	}
	
	@ResponseBody
	@RequestMapping(value="/deleteSclass/{sclassNo}")
	public String deleteSclass(@PathVariable(value="sclassNo")String sclassNo){
		SclassService.deleteSclass(sclassNo);
		return "success";
	}
	
	@ResponseBody
	@RequestMapping(value="/deleteSclassList")
	public String deleteSclassList(@RequestParam(value="array")String array){
		SclassService.deleteSclassList(array);
		return "success";
	}
	
	@ResponseBody
	@RequestMapping(value="/json/loadCollege")
	public List<College> jsonLoadCollege(){
		return collegeService.jsonLoadCollege();
	}
	
	@ResponseBody
	@RequestMapping(value="/json/loadMajor/{collegeNo}")
	public List<Major> jsonLoadMajor(@PathVariable(value="collegeNo")String collegeNo){
		return majorService.jsonLoadMajor(collegeNo);
	}
	
	@ResponseBody
	@RequestMapping(value="/json/loadGrade/{majorNo}")
	public List<Grade> jsonLoadGrade(@PathVariable(value="majorNo")String majorNo){
		return gradeService.jsonLoadGrade(majorNo);
	}
}
